package com.wang.users.pojo;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.wang.common.pojo.BasePojo;
import com.wang.common.util.ConstatFinalUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * 外事登记表 表
 *
 * @author ZjxMi
 */
@TableName(value = "at_users_activity")
@Data
@EqualsAndHashCode(callSuper=false)
public class AtUsersActivity extends BasePojo implements Serializable {
    @Serial
    private static final long serialVersionUID = -3620167882231412277L;

    @TableField
    private String workArrange;
    @TableField
    private String address;
    @TableField
    private Date currDate;
    @TableField
    private String organId;
    @TableField
    private Date backDate;
    @TableField
    private String note;

    @TableField
    private String usersId;
    @TableField
    private String leaderId;
    @TableField
    private String auditId;
    @TableField
    private Date auditTime;
    @TableField
    private int urgingNum;
    @TableField
    private Date proccedEndTime;

    /**
     * 字符串描述
     */
    @TableField(exist = false)
    private String leaveTypeStr;
    @TableField(exist = false)
    private String statusStr;

    /**
     * 对象描述
     */
    @TableField(exist = false)
    private AtUsersDesc usersDescObj;
    @TableField(exist = false)
    private AtUsersDesc leaderObj;
    @TableField(exist = false)
    private AtRbacAdmins auditObj;
    @TableField(exist = false)
    private AtUsersOrgan organObj;

    @Override
    public JSONObject getEnumsJson() {
        JSONObject enumsJson = super.getEnumsJson();
        AtUsersActivityEnum[] enumsArr = AtUsersActivityEnum.values();
        for (AtUsersActivityEnum enumsTemp : enumsArr) {
            String varName = enumsTemp.toString();
            String[] varNameArr = varName.split(ConstatFinalUtil.FINAL_JAVA_ENUMS_SPLIT);
            if (varNameArr.length == 2) {
                /* 条目 */
                JSONObject jsonEntryTemp = new JSONObject();
                jsonEntryTemp.put(ConstatFinalUtil.FINAL_ENUMSVAL, varName);
                jsonEntryTemp.put(ConstatFinalUtil.FINAL_CODE, enumsTemp.getCode());
                jsonEntryTemp.put(ConstatFinalUtil.FINAL_INFO, enumsTemp.getInfo());

                String jsonKey = varNameArr[0];
                /* 源数组 */
                JSONArray jsonArrVal = enumsJson.getJSONArray(jsonKey);
                if (Objects.isNull(jsonArrVal)) {
                    jsonArrVal = new JSONArray();
                }
                jsonArrVal.add(jsonEntryTemp);

                /* 存储最终结果 */
                enumsJson.put(jsonKey, jsonArrVal);
            }
        }
        return enumsJson;
    }

    @Override
    public String getStatusStr() {
        AtUsersActivityEnum[] enumsArr = AtUsersActivityEnum.values();
        for (AtUsersActivityEnum enumsTemp : enumsArr) {
            String varName = enumsTemp.toString();
            if (varName.startsWith("STATUSNEW_") && enumsTemp.getCode().equalsIgnoreCase(this.getStatus()) ) {
                this.statusStr = enumsTemp.getInfo();
                break;
            }
        }
        return statusStr;
    }
}